 /***ProtoExt By GYLite 2022-12-26
 * 功能注入类，注入一些功能，如Log日志打印包含帧率和帧频执行时间，判断运行时环境不存在的接口跳过执行的
*/
class ProtoExt {    
	public constructor() {
	}
    public static resumeAudioContext():void
    {
        let web = egret["web"];
        if (web.WebAudioDecode.ctx) {
            try {
                web.WebAudioDecode.ctx.close();
            }
            catch (e) {
            }
        }
        let win:any;
        win = window;
        web.WebAudioDecode.ctx = new (win["AudioContext"] || win["webkitAudioContext"] || win["mozAudioContext"])();
    }
	// private static _armatureVec:Array<dragonBones.Armature>;
	public static inject():void
	{
		let p:any;
        let win:any;
        win = window;
        egret.InputController.typingShow = (egret.nativeRender && egret.Capabilities.os == "Android")
        //运行时环境不存在FormData结构，我们使用自定义的方式
        if(win.FormData == null)
        {
            // Log.writeLog("FormData is null");
            win.FormData = (function(){
                function FormData(){}
                FormData.prototype.append = function(key, value){
                    this[key] = value;
                } 
                return FormData;
            }
            )();
        }                
       
        //获取帧频耗费时间
        p = egret.sys.SystemTicker.prototype;
        p.render = function (triggerByFrame, costTicker) {
			var playerList = this.playerList;
			var length = playerList.length;
			var t;
			if (length == 0) {
				return;
			}
			t = Date.now();
			this.callLaters();
			if (egret.sys.$invalidateRenderFlag) {
				this.broadcastRender();
				egret.sys.$invalidateRenderFlag = false;
			}
			for (var i = 0; i < length; i++) {
				playerList[i].$render(triggerByFrame, costTicker);
			}
			egret.sys.$requestRenderingFlag = false;
			Log.costRender = Date.now() - t;
            Log.costTicker = costTicker;
		};    
	}
}